//
//  SKYWKWebViewController.m
//  SkyonSDK_Example
//
//  Created by 张二帅 on 2018/6/12.
//  Copyright © 2018年 Skyon. All rights reserved.
//

#import "SKYWKWebViewController.h"
#import <WebKit/WebKit.h>

API_AVAILABLE(ios(8.0))
@interface SKYWKWebViewController ()<WKNavigationDelegate>
@property (strong, nonatomic) WKWebView *webView;

@end

@implementation SKYWKWebViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    if (@available(iOS 8.0, *)) {
        self.webView = [[WKWebView alloc] initWithFrame:self.view.bounds];
        [self.view addSubview:self.webView];
    }
    NSString *urlString = @"http://www.itaiping.com/pc/index/";
    urlString = @"http://smarket.tp95589.com/neiqin-score-mobile/scoreService.html";
    urlString = @"http://mall.itaiping.com/neiqin-score-mobile/goodsdetails?goodsId=c1844372-634d-4a7b-b2db-e8fddeca8fdb";
    urlString = @"http://baoxian.itaiping.com/sso/appLogin/login";
    [self.webView loadRequest:[[NSURLRequest alloc] initWithURL:[NSURL URLWithString:urlString]]];
    self.webView.navigationDelegate = self;
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    NSLog(@"%@",self.webView.navigationDelegate);
}

#pragma mark - WKNavigationDelegate
//当内容开始返回时调用
- (void)webView:(WKWebView *)webView didCommitNavigation:(null_unspecified WKNavigation *)navigation API_AVAILABLE(ios(8.0));{
//    [webView evaluateJavaScript:@"document.cookie = 'lgn_ur=918308266@qq.com';" completionHandler:^(id _Nullable rep, NSError * _Nullable error) {
//        if (error) {
//            NSLog(@"%@",error.localizedDescription);
//        }
//    }];
}
// 页面加载完成之后调用
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation API_AVAILABLE(ios(8.0)){
    [webView evaluateJavaScript:@"document.cookie" completionHandler:^(id _Nullable cookie, NSError * _Nullable error) {
        if (cookie != nil) {
            NSLog(@"document.cookie:%@",cookie);
        } else {
            NSLog(@"document.cookie error:%@",error.localizedDescription);
        }
    }];
}



@end
